import VueRouter from 'vue-router';

const Home = resolve => require(['pages/home/home.vue'], resolve);
const HomeNext = resolve => require(['pages/home/home-next.vue'], resolve);
const PersonalCenter = resolve => require(['pages/personal-center/personal-center.vue'], resolve);
const myRewards = resolve => require(['pages/my-rewards/my-rewards.vue'], resolve);
const rankList = resolve => require(['pages/rank-list/rank-list.vue'], resolve);
const questionsPage = resolve => require(['pages/questions-page/questions-page.vue'], resolve);
const activityRules = resolve => require(['pages/activity-rules/activity-rules.vue'], resolve);

const router = new VueRouter({
    routes: [
        { path: '/home', component: Home },
        { path: '/home-next', component: HomeNext },
        { path: '/personal-center', component: PersonalCenter },
        { path: '/my-rewards', component: myRewards },
        { path: '/rank-list', component: rankList },
        { path: '/questions-page', component: questionsPage },
        { path: '/activity-rules', component: activityRules },
    ]
})

//路由操作
router.beforeEach(function(to,from,next){
    if(to.path=='/'){
        next({
            path:'/home'
        })
    }else{
        next();
    }


    // next({
    //     path:'/home'
    // })
    // if(to.path=="/"){
    //     var isBind=sessionStorage.getItem("isBind");
    //     if(isBind=="true"){
    //         sessionStorage.setItem("login","true")
    //         next({
    //             path:"/logined"
    //         })
    //     }else{
    //         next({
    //             path:"/login"
    //         })
    //     }
    // }
    // else{
    //     if(to.path=="/login"){
    //         next();
    //     }else if(to.path=="/logined"){
    //         sessionStorage.setItem("login","true");
    //         next();
    //     }else{
    //         if(sessionStorage.getItem("login")=="false"){
    //             if(sessionStorage.getItem("isBind")=="true"){
    //                 next({path:"logined"});
    //             }else{
    //                 next({path:"login"});
    //             }
    //         }else{
    //             next();
    //         }
    //     }
    // }

})

export default router;